import React, { Component } from 'react'
import { Carousel } from 'antd-mobile'
import './TimeLimit.style.scss'

export default class TimeLimit extends Component {
    render() {
        return (
            <div className="timelimit">
                <div>
                    <h3>限时团购</h3>
                    <p>FLASH SALE<span>1/12</span></p>
                </div>
                <Carousel
                    autoplay={true}
                    infinite={true}
                    dots={false}
                >
                    {this.props.timelimit && this.props.timelimit.GROUP_BUY.map((val, index) => {

                        return (
                            <div className="item" key={index}>
                                <div className="imgCon">
                                    <img
                                        src={val.img}
                                        alt={index}
                                        style={{ width: '100%', verticalAlign: 'top' }}
                                        onLoad={() => {
                                            window.dispatchEvent(new Event('resize'));
                                        }}
                                    />
                                </div>
                                <div className="msg">
                                    <span className="time">{
                                        // (()=>{
                                        //     var date1 = val.endtime
                                        //     var d1 = new Date(date1);
                                        //     var t1 = d1.getTime();
                                        //     setInterval(() => {
                                        //         var d2 = new Date();
                                        //         var t2 = d2.getTime();
                                        //         var time = Math.abs(t1 - t2);
                                        //         var tian = parseInt(time / 1000 / 60 / 60 / 24);
                                        //         var shi = parseInt((time - tian * 24 * 60 * 60 * 1000) / 1000 / 60 / 60);
                                        //         var fen = parseInt((time - tian * 24 * 60 * 60 * 1000 - shi * 60 * 60 * 1000) / 1000 / 60);
                                        //         var miao = parseInt((time - tian * 24 * 60 * 60 * 1000 - shi * 60 * 60 * 1000 - fen * 60 * 1000) / 1000);
                                        //         var T = `${tian}天${shi}时${fen}分${miao}秒`
                                        //         document.getElementsByClassName('time')[index].innerHTML=T
                                        //     }, 1000)
                                        // })()
                                        
                                        "hello"
                                    }</span>
                                    <p>{val.title}</p>
                                    <i>￥{val.price}</i>
                                    <em>原价￥{val.original_price}</em>
                                </div>
                            </div>
                        )
                    })}
                </Carousel>
            </div>
        )
    }
}
